package web.user;

import bean.User;
import bean.Video;
import com.alibaba.fastjson.JSON;
import entity.UserEntity;
import entity.VideoEntity;
import util.FANREN;

import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UserDelete",urlPatterns = "/dao/update/userDelete")
public class UserDelete extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String jsonString = FANREN.getJson(request);
        System.out.println(jsonString);
        EntityManager em = (EntityManager) request.getAttribute("_entity.Manager");
        //删除一条记录
        User user = JSON.parseObject(jsonString,User.class);
        UserEntity userEntity = em.find(UserEntity.class,Integer.parseInt(user.getUid()));
        if(userEntity!=null)
            em.remove(userEntity);
        //删除一条记录
    }
}
